package dataStructure.recursive;

public class Queue8 {
    int max=8;
    int[] queue = new int[max];
    public static void main(String[] args) {
        Queue8 queue8 = new Queue8();
        queue8.check(0);
        System.out.printf("所有情况：%d",count);


    }
    //放置第 n 个皇后
    private void check(int n ){
        if (n==max){
            print();
            return;
        }

        for (int i=0;i<max;i++){
            queue[n]=i;
            if (judge(n)){
                check(n+1);
            }

        }
    }
    static int count=0;

    //n代表第几个皇后
    private boolean judge(int n){
        for (int i =0;i<n;i++){

            if (queue[i]==queue[n] || Math.abs(n-i) == Math.abs(queue[n]-queue[i])){
                return false;
            }

        }
        return true;
    }
    private  void print(){
        count++;
        for (int i = 0;i<queue.length;i++){
            System.out.print(queue[i]+" ");
        }
        System.out.println();
    }
}
